<template>
  <el-dialog
    title='编辑废气排放口'
    :visible.sync='state'
    :modal-append-to-body='false'
    :close-on-click-modal='false'
    :close-on-press-escape='false'
    @close='closeBox'>

    <el-form :model='form' :rules='rules' ref='form' size='small'>

      <!-- <el-row type='flex' class='row-bg' justify='space-between' align='middle'>
        <el-col :span='12' class='grid-content'>
          <el-form-item label='选择企业：' :label-width='formLabelWidth' prop='companyId'>

            <el-select size='medium' v-model="form.companyId" placeholder="请选择" @change="companyChange">
              <el-option v-for="item in companyList" :key="item.id" :label="item.name" :value="item.id">{{item.name}}</el-option>
            </el-select>

          </el-form-item>
        </el-col>
      </el-row>

      <el-row type='flex' class='row-bg' justify='space-between' align='middle'>
        <el-col :span='12' class='grid-content'>
          <el-form-item label='选择废气：' :label-width='formLabelWidth' prop='wasteId'>

            <el-select size='medium' v-model="form.wasteId" placeholder="请选择">
              <el-option v-for="item in wasteList" :key="item.id" :label="item.name" :value="item.id">{{item.name}}</el-option>
            </el-select>

          </el-form-item>
        </el-col>
      </el-row> -->

      <el-row type='flex' class='row-bg' justify='space-between'>
        <el-col :span='12' class='grid-content'>

          <el-form-item label='排放口名称：' :label-width='formLabelWidth' prop='name'>
            <el-input size='small' v-model='form.name' autocomplete='off'></el-input>
          </el-form-item>

        </el-col>
      </el-row>

      <el-row type='flex' class='row-bg' justify='space-between'>
        <el-col :span='12' class='grid-content'>

          <el-form-item label='经度：' :label-width='formLabelWidth' prop='longitude'>
            <el-input size='small' v-model='form.longitude' autocomplete='off'></el-input>
          </el-form-item>

        </el-col>
      </el-row>

      <el-row type='flex' class='row-bg' justify='space-between'>
        <el-col :span='12' class='grid-content'>

          <el-form-item label='纬度：' :label-width='formLabelWidth' prop='latitude'>
            <el-input size='small' v-model='form.latitude' autocomplete='off'></el-input>
          </el-form-item>

        </el-col>
      </el-row>

      <el-row type='flex' class='row-bg' justify='space-between'>
        <el-col :span='12' class='grid-content'>

          <el-form-item label='高度(m)：' :label-width='formLabelWidth' prop='height'>
            <el-input size='small' v-model='form.height' autocomplete='off'></el-input>
          </el-form-item>

        </el-col>
      </el-row>

      <el-row type='flex' class='row-bg' justify='space-between'>
        <el-col :span='12' class='grid-content'>

          <el-form-item label='直径(m)：' :label-width='formLabelWidth' prop='diameter'>
            <el-input size='small' v-model='form.diameter' autocomplete='off'></el-input>
          </el-form-item>

        </el-col>
      </el-row>

      <el-row type='flex' class='row-bg' justify='space-between'>
        <el-col :span='12' class='grid-content'>

          <el-form-item label='温度(℃)：' :label-width='formLabelWidth' prop='temperature'>
            <el-input size='small' v-model='form.temperature' autocomplete='off'></el-input>
          </el-form-item>

        </el-col>
      </el-row>

      <el-divider></el-divider>
      <el-row justify='end' align='middle'>
        <el-col :span='24'>
          <el-form-item style='float: right'>
            <el-button @click="cancel('form')">取 消</el-button>
            <el-button type='primary' @click="submit('form')">确 定</el-button>
          </el-form-item>
        </el-col>
      </el-row>


      <!-- <el-form-item>
        <el-button @click="cancel('form')">取 消</el-button>
        <el-button type='primary' @click="submit('form')">确 定</el-button>
      </el-form-item> -->
    </el-form>
  </el-dialog>
</template>
<script>


export default {
  components: {

  },
  props: ['editItem'],
  computed: {},
  data() {
    return {
      formLabelWidth: '120px',
      state: true,

      sigData: null,
      companyList: [],
      wasteList: [],

      form: {
        name: '',
        // companyId: '',
        // wasteId: '',

        longitude: '',
        latitude: '',
        height: '',
        diameter: '',
        temperature:'',

      },
      rules: {
        // companyId: [{ required: true, message: '请选择企业', trigger: 'change' }],
        // wasteId: [{ required: true, message: '请选择废气', trigger: 'change' }],

        name: [{ required: true, message: '请输入排放口名称', trigger: 'blur' }],
        longitude: [{ required: true, message: '请输入经度', trigger: 'blur' }],
        latitude: [{ required: true, message: '请输入纬度', trigger: 'blur' }],
        height: [{ required: true, message: '请输入高度', trigger: 'blur' }],
        diameter: [{ required: true, message: '请输入直径', trigger: 'blur' }],
        temperature: [{ required: true, message: '请输入温度', trigger: 'blur' }],

      },
    };
  },
  created() {
    this.form = Object.assign({}, this.form, this.editItem);
    // this.companyLists();
    // this.wasteLists(this.form.companyId);
    // this.getSig();
  },
  mounted() {},
  methods: {
    closeBox() {
      this.state = false;
      this.$ge.$emit('biz-waste-vocs-port-change-search');
    },
    cancel(formName) {
      this.state = false;
      this.$refs[formName].resetFields();
    },
    //查询企业列表
    // companyLists() {
    //   this.$get('/biz-company/list', {})
    //     .then((result) => {
    //       if (result.code == 200 && result.data) {
    //         this.companyList = result.data;
    //       }
    //     })
    //     .catch((error) => {
    //       this.companyList = [];
    //     });
    // },
    // companyChange(id) {
    //   if(!id) {
    //     this.wasteList = [];
    //     return;
    //   }
    //   this.wasteLists(id);
    // },
    //查询企业列表
    // wasteLists(companyId) {
    //   this.$get('/biz-pollution-source/list', {
    //     type: 'VOCS',
    //     companyId: companyId
    //   })
    //     .then((result) => {
    //       if (result.code == 200 && result.data) {
    //         this.wasteList = result.data;
    //       }
    //     })
    //     .catch((error) => {
    //       this.wasteList = [];
    //     });
    // },
    // getSig() {
    //   this.$get('/oss/getUploadOssSignature')
    //     .then((result) => {
    //       if (result.code == 200 && result.data) {
    //         this.sigData = result.data;
    //       }
    //     })
    //     .catch((error) => {
    //       this.sigData = null;
    //     });
    // },
    submit(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$WLoading();
 
          var param = {};
          param = Object.assign({}, this.form, param);

          this.$postJson('/biz-pollution-source-discharge-port/update', param)
            .then((result) => {
              if (result.code == 200) {
                this.$message.success(result.msg);

                //关闭弹框并刷新列表
                this.closeBox(formName);
              } else this.$message.error(result.msg);
              this.$cancelLoading();
            })
            .catch((error) => {
              //添加用户异常
              this.$message.error('添加失败');
              this.$cancelLoading();
            });
        } else {
          console.log('用户填写有误！');
          return false;
        }
      });
    },

  },
};
</script>

<style>
.el-select {
  width: 100%;
}

.vue-treeselect__input {
  border: 0 !important;
}

.el-form-item__content {
  text-align: left;
}

/* 上传样式 start */
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}

.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}

.avatar {
  width: 178px;
  height: 178px;
  display: block;
}

/* 上传样式 end */
</style>
